<?php
	if(!isset($_GET['act'])) {die(); }
	$Msg_CONFIRM = '';
	MYDCONN();
	if($_GET['act']==1) {
	$CheckItem = $GLOBALS['MYD']->db_array("SELECT ref FROM ccenter_requestarticles
		WHERE RefRequest = 0
			AND racUser = {$_SESSION[$SESSID]} AND racOffice = {$_SESSION[$SESSOF]}");
	if (!isset($CheckItem[1])) { echo '<script charset="utf-8" type="text/javascript">alert(\'O Pedido esta vazio.\');</script>';
	die(); }
	 $GLOBALS['MYD']->db_query("INSERT INTO ccenter_requests
				(RefUser, RefOffice, RefDomain, Observations, TimeCreated, Status)
				VALUES 
				({$_SESSION[$SESSID]},{$_SESSION[$SESSOF]},1,'{$_POST['Observations']}','{$sysTime}',1)"); 
				$Msg_CONFIRM = '<div class="Confirm">Opera��o Executada.</div>';
		$GetItem = $GLOBALS['MYD']->db_array("SELECT ref FROM ccenter_requests
		WHERE RefUser = {$_SESSION[$SESSID]} AND RefOffice = {$_SESSION[$SESSOF]}
		ORDER BY ref DESC LIMIT 0,1");
		$GLOBALS['MYD']->db_query("UPDATE ccenter_requestarticles
			SET RefRequest = {$GetItem[1]['ref']}
			WHERE RefRequest= 0
			AND racUser = {$_SESSION[$SESSID]} AND racOffice = {$_SESSION[$SESSOF]}");
	} elseif($_GET['act']==2) {
	$GLOBALS['MYD']->db_query("UPDATE ccenter_requests
			SET 
			TimeAproval = '{$sysTime}',
			RefAproval = {$_SESSION[$SESSID]},
			Status = {$_POST['Status']}
			WHERE Ref = {$_POST['Ref']}");
	} elseif($_GET['act']==6) {
	$GLOBALS['MYD']->db_query("UPDATE ccenter_requests
			SET 
			TimeReceived = '{$sysTime}',
			RefReceived = {$_SESSION[$SESSID]},
			Status = 6
			WHERE Ref = {$_POST['Ref']}");
	} elseif($_GET['act']==3) {
	$GLOBALS['MYD']->db_query("INSERT INTO ccenter_requestarticles
			(RefArticle,RefRequest,Quantity,se,seTYPE,ArticleDescription,racUser,racOffice)
			VALUES
			({$_POST['Article']},{$_POST['Ref']},'{$_POST['Quant']}',{$_POST['Use']},{$_POST['UseTYPE']},'{$_POST['ArticleDescription']}',{$_SESSION[$SESSID]},{$_SESSION[$SESSOF]})");
		$Msg_CONFIRM = '<script charset="utf-8" type="text/javascript">replaceUrl(\'reqItems\',\'Modules/CentrodeCustos/Lib/list_requests_article.php?Ref='.$_POST['Ref'].'\');</script>';
	} elseif($_GET['act']==4) {
	$GLOBALS['MYD']->db_query("UPDATE ccenter_requestarticles
			SET 
			Status = 5
			WHERE Ref = {$_GET['id']}");
		$Msg_CONFIRM = '<script charset="utf-8" type="text/javascript">replaceUrl(\'reqItems\',\'Modules/CentrodeCustos/Lib/list_requests_article.php?Ref='.$_POST['Ref'].'\');</script>';
	} elseif($_GET['act']==5) {
	$GLOBALS['MYD']->db_query("UPDATE ccenter_requestarticles
			SET 
			ArticleDescription = '{$_POST['ArticleDescr']}',
			Status = {$_POST['ArticleStatus']},
			Quantity = {$_POST['ArticleQuant']},
			seTYPE = {$_POST['ArticleUseTYPE']},
			se  = {$_POST['ArticleUse']}
			WHERE Ref = {$_POST['ArticleID']}");
	}
	if (isset($Msg_ERROR)) {
		$Msg_ERROR = "Erro, não foi possível concluír a operação.";
	} elseif($Msg_CONFIRM != ''){
			echo $Msg_CONFIRM;
	}
?>